<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>文件管理</title>
    <link rel="stylesheet" href="${base}/layui/css/layui.css">
    <style>
    	.hide {display: none;}
    	.img90{width: 90px;height: 90px;}
    	.layui-bg-black{width: 160px;    height: 140px;margin-right: 30px;float: left;text-align: center;font-size: 14px;color: #000!important;background-color: #fff!important;}
    </style>
</head>
<body  class="layui-layout-body">
<#include "/common/left.flt">	
<div class="layui-main" style="position: absolute;left: 300px;top: 50px;" >
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  <legend>操作提示</legend>
</fieldset>
   
<blockquote class="layui-elem-quote layui-quote-nm">
 	<div class="layui-input-inline">
 		<form class="layui-form" action="">
 		<div class="layui-form-item">
		    <label class="layui-form-label">选择项目</label>
		    <div class="layui-input-block">
		      <select name="pid" id="pid" lay-filter="pidChanged" class="layui-select" >
		      </select>
		    </div>
		</div>
		</form>
 		<button class="layui-btn" id="addFile" ><img alt="" src="${base}/images/upload.png" width="16px" height="16px" /> 上传文件</button>
 		<button class="layui-btn" id="addFile2" ><img alt="" src="${base}/images/upload.png" width="16px" height="16px" /> 上传影像文件</button>
 		
 		<button class="layui-btn" id="addFolder" ><img alt="" src="${base}/images/uploadto.png" width="16px" height="16px" /> 上传文件夹</button>
 		<button class="layui-btn" id="del" ><img alt="" src="${base}/images/delete.png" width="16px" height="16px" />删除</button>
 		<button class="layui-btn" id="new" ><img alt="" src="${base}/images/new.png" width="16px" height="16px" /> 新建文件夹</button>
 	</div>
</blockquote> 
<div style="overflow:scroll; padding-bottom: 100px;margin-bottom: 200px;height: 700px;">
<#list dataList as one>
     	<div class="layui-bg-black" >
     	<input type="checkbox" name="id" value="${one.id}" />
     	<#if one.folder gt 0>
     	<a href="${base}/index/fileList?parentid=${one.id}"><img alt="${one.alias}" src="${base}/images/folder.png" class="img90"></a>
     	<#else>
     	<img alt="${one.alias}" src="${base}/images/file.png"  class="img90">
     	</#if>
     	<p>${one.alias}</p></div>
</#list>
</div>
</div>
<form action="${base}/util/uploadFile" method="post" name="uploadForm" enctype="multipart/form-data" id="uploadForm" class="hide" >
	<input name="pid" type="hidden" value="${pid}" />
	<input name="parentid" type="hidden" value="${parentid}" />
    <input name="pic" type="file" id="pic" class="hide"/>
</form>

<form action="${base}/util/uploadFolder" method="post" name="uploadForm1" enctype="multipart/form-data" id="uploadForm1" class="hide" >
	<input name="pid" type="hidden" value="${pid}" />
	<input name="parentid" type="hidden" value="${parentid}" />
    <input name="folder" type="file" id="folder" class="hide" multiple="multiple"  webkitdirectory/>
</form>
</body>
<script src="${base}/js/jquery-2.1.4.min.js" type="text/javascript"></script>
<script src="${base}/js/jquery.form.js" type="text/javascript"></script>
<script src="${base}/layui/layui.all.js"></script>
<script type="text/javascript">
$("#pid").val("${pid}");
layui.use(['form', 'layer'], function () {
    var form = layui.form;
    var layer = layui.layer;
    form.on('select(pidChanged)', function (data) {
       window.location.href = "${base}/fileList?parentid=${parentid}&pid=" + data.value;
    });
});


var dcmCheck = false;
$("#addFile").click(function (){
	$("#pic").click();
	dcmCheck = false;
});

$("#addFile2").click(function (){
	$("#pic").click();
	dcmCheck = true;
});
$("#addFolder").click(function (){
	$("#folder").click();
	dcmCheck = false;
});


$("#pic").change(function (){
	if (dcmCheck) {
		var fileName = $("#pic").val();
		var this_len = fileName.length;
		var ext = fileName.substring(this_len - 4, this_len);
		console.log(ext);
		if (".dcm" != ext ){
			layer.alert("不是dcm文件");
			return;
		} 
	} 

 	var options = {
         success:  showResponse,  //处理完成的回调函数
         resetForm: false
    };
    $("#uploadForm").ajaxSubmit(options);
});
$("#folder").change(function (){
	var options = {
         success:  showResponse,  //处理完成的回调函数
         resetForm: false
	};
 	$("#uploadForm1").ajaxSubmit(options);
});


$("#new").click(function(){
	layer.open({
	    type: 1
	    ,id: 'layer1' //防止重复弹出
	    ,area:['400px', '260px']
	    ,content: '<div class="layui-input-inline" style="margin-top: 60px;"><label class="layui-form-label">文件名</label><input type="text" name="name" id="name"  placeholder="请输入文件名"  class="layui-input" style="width: 200px;"></div>'
	    ,btn: '确定'
	    ,btnAlign: 'c' //按钮居中
	    ,shade: 0 //不显示遮罩
	    ,yes: function(){
	    	var name = $("#name").val();
	        $.post("${base}/index/folderAdd",
	        		{"pid":${pid},"name":name,"parentid":${parentid}},function(data){ 
	        			layer.alert("操作成功！");
	        			window.location.reload();
	        		}
	        );
	    }
	});
});

$("#del").click(function (){
	var values = "";
	var i = 0;
	$("input[name='id']").each(function(){
		if ($(this).is(':checked')){
			values = values + $(this).attr("value") +",";
			i = i + 1;
		}
	});
	if (i > 0){
		$.post("${base}/index/fileDel",
        		{"ids":values},function(data){ 
        			layer.alert(data);
        			window.location.reload();
        		}
        );
	} else {
		layer.msg("没有选择记录！");
	}
});
function showResponse(data){
	layer.alert("操作成功！");
	window.location.reload();
}


</script>
</html>